﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Lists;
using ListForms;

namespace ListForms
{
    public partial class FrmDanhMucNhomVatTuHangHoa : ListForms.FrmBaseListForm
    {
        public FrmDanhMucNhomVatTuHangHoa()
        {
            InitializeComponent();
        }

        private void FrmDanhMucNhomVatTuHangHoa_Load(object sender, EventArgs e)
        {
            gridDSDoiTuong.Visible = false;
            tlvDanhMucNhomVatTuHangHoa.OptionsBehavior.Editable = false;
        }
        void Instance_Change()
        {
            LoadData();
        }
        public override void LoadData()
        {
            try
            {
                tlvDanhMucNhomVatTuHangHoa.DataSource = DanhMucNhomVatTuHangHoa.Filter("LienQuanDenKho = 1").DataView;
                InitGridColumnNews();
            }
            catch
            {
            }
        }
        public void InitGridColumnNews()
        {
            foreach (DevExpress.XtraTreeList.Columns.TreeListColumn column in tlvDanhMucNhomVatTuHangHoa.Columns)
            {
                column.Visible = false;
            }

            tlvDanhMucNhomVatTuHangHoa.Columns["Ma"].Caption = "Mã";
            tlvDanhMucNhomVatTuHangHoa.Columns["Ma"].Visible = true;
            tlvDanhMucNhomVatTuHangHoa.Columns["Ten"].Caption = "Tên";
            tlvDanhMucNhomVatTuHangHoa.Columns["Ten"].Visible = true;

            tlvDanhMucNhomVatTuHangHoa.Columns["PhuongPhapTinhGiaTonKhoID"].Caption = "Phương pháp tính giá tồn kho";
            tlvDanhMucNhomVatTuHangHoa.Columns["PhuongPhapTinhGiaTonKhoID"].Visible = true;
            tlvDanhMucNhomVatTuHangHoa.Columns["PhuongPhapTinhGiaTonKhoID"].VisibleIndex = 3;

            DevExpress.XtraEditors.Controls.LookUpColumnInfo colTen = new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Tên", "Tên", 20);
            DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit repPhuongPhapTinhGiaTonKho = new DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit();
            repPhuongPhapTinhGiaTonKho.Columns.Add(colTen);
            repPhuongPhapTinhGiaTonKho.ValueMember = "ID";
            repPhuongPhapTinhGiaTonKho.DisplayMember = "Ten";
            repPhuongPhapTinhGiaTonKho.DataSource = DanhMucPhuongPhapTinhGiaTonKho.Instance.DataView;
            DevExpress.XtraTreeList.Columns.TreeListColumn colPhuongPhapTinhGiaTonKho = tlvDanhMucNhomVatTuHangHoa.Columns["PhuongPhapTinhGiaTonKhoID"];
            colPhuongPhapTinhGiaTonKho.ColumnEdit = repPhuongPhapTinhGiaTonKho;
        }

        private void TlvDanhMucNhomVatTuHangHoa_DoubleClick(object sender, EventArgs e)
        {
            Edit();        
        }
        public override void CreateNew()
        {
            try
            {
                FrmEditNhomVatTuHangHoa frm = new FrmEditNhomVatTuHangHoa(null);
                frm.ShowDialog();
            }
            catch(Exception ex)
            {
            }
        }
        protected override void Edit()
        {
            try
            {
                Guid id =(Guid) tlvDanhMucNhomVatTuHangHoa.Selection[0]["ID"];
                FrmEditNhomVatTuHangHoa frm = new FrmEditNhomVatTuHangHoa(DanhMucNhomVatTuHangHoa.Instance.GetByID(id));
                frm.ShowDialog();
            }
            catch (Exception ex)
            {
            }
        }
        protected override void Delete()
        {
            try
            {
               // DanhMucTaiKhoan dm = DanhMucTaiKhoan.GetByFilterExpession("(SoHieu NOT LIKE '0%') AND ID NOT IN ('5cd7e23b-59f7-4394-a610-e7b0699843a3', 'c5d18d05-8295-4e72-a1b1-419dbfa8735b', '38d3c97a-3404-49a5-b82e-b9cae645493a', '959e397f-933c-40f7-9c9d-9da044b2a2d5', 'abe17641-b1a7-4752-b655-2db8a203c7cf', 'a8bd0066-cc99-4b93-be07-e149513bb440', 'd6fe348f-a189-41b2-a634-e7115a7d865b', '51139f2f-b8aa-4345-9fe1-b5bd9c28bdcc', 'dc92d609-6d82-40d3-bbdf-c1d7ae7db789', '642298bb-584d-414d-8e32-08b2ba8f1c36', '2c25beda-c3c2-461d-84f4-9cefe3bb2d84', 'ba83912f-d77c-48e0-9791-caf469dc158d', '3ce9adab-56de-4795-b881-82e85c2e261c', '5bc571b4-2bbf-47a2-a85a-abb5a8759dfc', '05394666-5e9c-40f7-928b-9018557a22ec', 'd8d7e7d8-4822-4cdf-8bb1-ed68d9aa9411', '33a5b758-1b19-4278-ac2f-334838f87417', '76069669-2fec-45e5-9682-a79f3b833136', 'd51bdcfc-7aa7-4a1c-9cff-c5097048378d', '17b2391b-481e-426b-ab7a-4997782f671b', 'd74f239f-d957-4fb6-b0af-13a0554128f8', '3f7d81ee-4e3e-4ba0-9eb4-c1147b16d59d', '551378f6-ceb3-43fc-9ca5-1622eecca1e2', '4da70370-292b-444e-99c5-adbdaad7725a', 'aa252fca-2b94-44ae-adc4-0bd1734fab2b', '5417cf46-570c-4ab0-86b5-ac1794a7243c', 'acbc9bb9-11c3-4bf8-84ff-89e29ef0bbd3', '899b6865-4532-4e99-8d9a-ac7fed0bb212', 'd0d4d0a1-bbcd-4237-9f19-dedfdc6bcb2a', 'b012f2e7-d8be-4efc-b758-a6622f9a224f', '2e09b8b9-3e01-4c22-a86f-fac25b41026b', '51f21d32-14f2-4712-b97a-b003b4dd0072', 'db05efc0-5659-4ad9-90fa-976a5faa1ef2', 'cfe93cbf-9e58-40fa-b247-0702b9731764', '60ec8ad3-55f2-4d12-ac78-3b888e3da7b1', 'ac2aa614-5426-40fa-9bca-43e86ef5a3a7')");
                DanhMucTaiKhoan dm = DanhMucTaiKhoan.GetByFilterExpession("ID NOT IN (CONVERT('{7F901912-DD67-47B9-A5B3-B702B9F84680}','System.Guid'))");// AND ID NOT IN ('5cd7e23b-59f7-4394-a610-e7b0699843a3', 'c5d18d05-8295-4e72-a1b1-419dbfa8735b', '38d3c97a-3404-49a5-b82e-b9cae645493a', '959e397f-933c-40f7-9c9d-9da044b2a2d5', 'abe17641-b1a7-4752-b655-2db8a203c7cf', 'a8bd0066-cc99-4b93-be07-e149513bb440', 'd6fe348f-a189-41b2-a634-e7115a7d865b', '51139f2f-b8aa-4345-9fe1-b5bd9c28bdcc', 'dc92d609-6d82-40d3-bbdf-c1d7ae7db789', '642298bb-584d-414d-8e32-08b2ba8f1c36', '2c25beda-c3c2-461d-84f4-9cefe3bb2d84', 'ba83912f-d77c-48e0-9791-caf469dc158d', '3ce9adab-56de-4795-b881-82e85c2e261c', '5bc571b4-2bbf-47a2-a85a-abb5a8759dfc', '05394666-5e9c-40f7-928b-9018557a22ec', 'd8d7e7d8-4822-4cdf-8bb1-ed68d9aa9411', '33a5b758-1b19-4278-ac2f-334838f87417', '76069669-2fec-45e5-9682-a79f3b833136', 'd51bdcfc-7aa7-4a1c-9cff-c5097048378d', '17b2391b-481e-426b-ab7a-4997782f671b', 'd74f239f-d957-4fb6-b0af-13a0554128f8', '3f7d81ee-4e3e-4ba0-9eb4-c1147b16d59d', '551378f6-ceb3-43fc-9ca5-1622eecca1e2', '4da70370-292b-444e-99c5-adbdaad7725a', 'aa252fca-2b94-44ae-adc4-0bd1734fab2b', '5417cf46-570c-4ab0-86b5-ac1794a7243c', 'acbc9bb9-11c3-4bf8-84ff-89e29ef0bbd3', '899b6865-4532-4e99-8d9a-ac7fed0bb212', 'd0d4d0a1-bbcd-4237-9f19-dedfdc6bcb2a', 'b012f2e7-d8be-4efc-b758-a6622f9a224f', '2e09b8b9-3e01-4c22-a86f-fac25b41026b', '51f21d32-14f2-4712-b97a-b003b4dd0072', 'db05efc0-5659-4ad9-90fa-976a5faa1ef2', 'cfe93cbf-9e58-40fa-b247-0702b9731764', '60ec8ad3-55f2-4d12-ac78-3b888e3da7b1', 'ac2aa614-5426-40fa-9bca-43e86ef5a3a7')");
            
                //DataView vi = new DataView(DanhMucTaiKhoan.Instance.DataTable, filterExpression, "SoHieu", DataViewRowState.CurrentRows);
                return;
                Guid id = (Guid)tlvDanhMucNhomVatTuHangHoa.Selection[0]["ID"];
                Lists.NhomVatTuHangHoa deletedObj = DanhMucNhomVatTuHangHoa.Instance.GetByProperty("ID", id);
                if (deletedObj != null)
                {
                    if (MessageBox.Show("Bạn có thực sự muốn xóa NhomVatTuHangHoa", "Xác nhận", MessageBoxButtons.YesNo) == DialogResult.No)
                        return;
                    else
                        deletedObj.DeleteFromDB();
                }
            }
            catch (Exception ex)
            {
            }
        }
    }
}
